package evo.springboot.service;

import com.alibaba.dubbo.config.annotation.Service;
import evo.springboot.mapper.StudentMapper;
import evo.springboot.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

@Component
@Service(interfaceClass = StudentService.class,version = "1.0.0",timeout = 3000000)
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper mapper;
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public Student queryId(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer queryAll() {
        Integer allStuCount = (Integer) redisTemplate.opsForValue().get("allStuCount");
        if(null == allStuCount){
            allStuCount = mapper.selectAllStudentCount();

            redisTemplate.opsForValue().set("allStuCount",allStuCount,100, TimeUnit.SECONDS);
        }
        return allStuCount;
    }
}


